function [] = largest_representable_number(r,L,M,x_max)
    % integer part
    Pi = 0;
    Pi_bin = zeros(1,M);
    if(M > 0)
        fprintf('Integer part:\n');
        fprintf('P_i=P_i+b*r^i\n\n');
        fprintf('i\tP_i\n');
        fprintf('----------------------\n');
        for i = 0:M-1,
           P_prev = Pi;
           Pi = Pi + x_max*r^i;
           Pi_bin(i+1) = x_max;
           fprintf('%d\t%.32f+%d*%d^%d=%.32f\n',i,P_prev,x_max,r,i,Pi);
        end
    end
    
    disp(' ');

    % fractional part
    Pf = 0;
    Pf_bin = zeros(1,L);
    fprintf('Fractional part:\n');
    fprintf('P_f=P_f+b*r^-i\n\n');
    fprintf('i\tP_f\n');
    fprintf('----------------------\n');
    for i = 1:L,
       P_prev = Pf;
       Pf = Pf + x_max*r^-i;
       Pf_bin(i) = x_max;
       fprintf('%d\t%.32f+%d*%d^-%d=%.32f\n',i,P_prev,x_max,r,i,Pf);
    end

    bin_str = '';
    for i = 1:M,
        bin_str = strcat(bin_str, num2str(Pi_bin(i)));
    end
    bin_str = strcat(bin_str, '.');
    for i = 1:L,
        bin_str = strcat(bin_str, num2str(Pf_bin(i)));
    end

    disp(' ');
    fprintf('%s = %.32f\n', bin_str,Pi+Pf);
    disp(' ');
end